<?php
if (!defined("EXPONENT")) exit("");

// include id3
include(BASE . "subsystems/getid3/getid3.php");
include(BASE . "modules/musicsmodule/core.php");
$getid3 = new getID3();

exponent_flow_set(SYS_FLOW_PROTECTED,SYS_FLOW_ACTION);
$album = $db->selectObject('listing',"list_type = 2 AND id = " . intval($_REQUEST['id']));
if ($album != null) {
	// for all musics in this album
			$musics=$db->selectObjects('musics','album_id='.intval($_REQUEST['id']));
			for($j=0; $j<count($musics); $j++) {
				$musics[$j]->downloadable=$album->downloadable;
				$musics[$j]->singer_search = htmlspecialchars($musics[$j]->singer);
				if ($musics[$j]->high_quality == 0) {
				$musics[$j]->high_quality = '';
			} else {
				$file = $db->selectObject('file', 'id='.$musics[$j]->high_quality);
				$musics[$j]->high_quality_id=$musics[$j]->high_quality;
				$musics[$j]->high_quality = $file->directory.$file->filename;
				  if (file_exists($musics[$j]->high_quality))
				{
				  $file_info = $getid3->analyze($musics[$j]->high_quality); 				  
				  //getid3_lib::CopyTagsToComments($file_info); 
				  $musics[$j]->bitrate=round($file_info['bitrate']/1000,0);
				  $musics[$j]->fileformat=$file_info['fileformat'];
				  $file_info=$file_info['playtime_string'];
				  $musics[$j]->file_length = $file_info;
				  
				}
			}
				
				if ($musics[$j]->sound_trackmix == 0) {
				$musics[$j]->sound_trackmix = '';
			} else {
				$file = $db->selectObject('file', 'id='.$musics[$j]->sound_trackmix);
				$musics[$j]->sound_trackmix = $file->directory.$file->filename;
				}
				
				if ($musics[$j]->sheet_music == 0) {
				$musics[$j]->sheet_music = '';
			} else {
				$file = $db->selectObject('file', 'id='.$musics[$j]->sheet_music);
				$musics[$j]->sheet_music = $file->directory.$file->filename;
				}
				
				if ($musics[$j]->demo == 0) {
				$musics[$j]->demo = '';
			} else {
				$file = $db->selectObject('file', 'id='.$musics[$j]->demo);
				$musics[$j]->demo = $file->directory.$file->filename;
				}
				
				// get composer name
				$composer=$db->selectObject('listing',"list_type = 1 AND id = {$musics[$j]->composer_id}");
				$composer_name='';
				if ($composer)
				{
					$composer_name=$composer->name;
				}
				$musics[$j]->composer_name =$composer_name;
				$musics[$j]->old_info =$musics[$j]->info;
				// for tooltip
				$musics[$j]=musicsmodule::make_info($musics[$j]);
				
				// what next?
				if ($musics[$j]->id == intval($_GET['id']))
					$music=$musics[$j];
			}
	
	if ($album->file_id!=0) {
		$file = $db->selectObject('file', "id=".$album->file_id);
		$album->picpath = $file->directory."/".$file->filename;
	} else {
		$album->picpath = "";
	}
	
	$template = new template("musicsmodule",'_play_album');
	$template->assign('album',$album);
	$template->register_permissions(array('administrate','configure'),$loc);
	$template->assign('musics',$musics);
	
	//
	$file_name=create_playlist($musics);
	$template->assign('plist',$file_name);
	$template->output();
} 
else {
	echo SITE_404_HTML;
}

?>
